package net.melon.sysres.cfg;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.inject.Inject;

import net.esj.basic.core.engine.config.AbstractConfiguration;
import net.esj.basic.core.engine.config.MelonConfig;
import net.melon.sysres.manager.SystemManager;
import net.melon.sysres.pojo.SysProperty;

import org.apache.commons.lang.StringUtils;

public class DatabaseConfiguration extends AbstractConfiguration{

	private SystemManager systemManager;
	
	@Inject
	public void setSystemManager(SystemManager systemManager) {
		this.systemManager = systemManager;
	}

	@Override
	protected String doGetProperty(String key) {
		List<SysProperty> list = systemManager.loadProperties(false);
		for(SysProperty p : list){
			if(StringUtils.equals(p.getCode(), key)){
				return p.getValue();
			}
		}
		return null;
	}

	@PostConstruct
	public void init(){
		MelonConfig.registryConfiguration(this);
	}
}
